//插入排序的递归解法
#include <iostream>
//n为arr长度
void insert_sort(int arr[], int n);

void insert_sort(int arr[], int n)
{
    if (n == 1)
        return ;
    insert_sort(arr, n-1);
    int key = arr[n-1];
    int i = n - 2;
    while (i >= 0 && arr[i] > key)
    {
        arr[i+1] = arr[i];
        i--;
    }
    arr[i+1] = key;
    
}
int main()
{
    using namespace std;
    int arr[5] = {5, 24, -4, 17, 0};
    insert_sort(arr, 5);
    for (int i = 0; i < 5; i++)
    {
        cout << arr[i] << endl;
    }

    return 0;
}